<template>
   <div>
        <h2 algin="center">用户详情注册表 登录人:{{ route.query.name }}</h2>
        <table class="table table-bordered">
            <tr>
                <td>真实姓名：</td>
                <td><input type="text" v-model="state.U_Name" /></td>
            </tr>
            <tr>
                <td>用户类型</td>
                <td>
                  <select v-model="state.UT_Id">
                    <option value="0">--请选择--</option>
                    <option :value="item.UT_Id" v-for="item in list">{{ item.UT_Name }}</option>
                  </select>
                </td>
            </tr>
            <tr>
                <td>用户联系方式</td>
                <td><input type="text" v-model="state.U_Phone" maxlength="11" /></td>
            </tr>
            <tr>
                <td>出生日期</td>
                <td><input type="date" v-model="state.U_Date" /></td>
            </tr>
            <tr>
                <td>性别</td>
                <td>
                    <input type="radio" name="sex" :value="0" checked v-model="state.U_Sex" />男
                    <input type="radio" name="sex" :value="1" v-model="state.U_Sex" />女
                </td>
            </tr> 
            <tr>
                <td></td>
                <td><input type="button" value="保存" @click="add" class="btn btn-success" />
                    <input type="button" value="返回"  class="btn btn-primary" /></td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import {reactive,ref,toRefs,onMounted} from 'vue'
import { useRouter,useRoute } from 'vue-router';
import axios from 'axios';
const router=useRouter();
const route=useRoute();
let data:any=reactive({
    list:[],
    state:{
        UL_Id:route.query.id,
        UT_Id:0,
        U_Name:'',
        U_Phone:'',
        U_Sex:'',
        U_Date:'',
    }
})
let{state,list} =toRefs(data);
onMounted(()=>{
    Seltype();
})
const Seltype=()=>{
    axios({
        url:"/api/Users/Seltype",
        method:'get',
    })
    .then(res=>{
        console.log(res.data.data);
        list.value=res.data.data;
    })
}
const add=()=>{
    axios({
        url:"/api/Users/UserAdd",
        method:'post',
        data:state.value
    })
    .then(res=>{
        if(res.data.data>0)
        {
            alert('完善成功');
            router.push('/main');
        }
        else
        {
            alert('完善失败');
        }
    })
}

</script>

<style>

</style>